﻿using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using Microsoft.Commerce.Proxy.TransactionService.v201001;
using System;

namespace TestWebApplication.CommerceTransaction.APIs
{
    public class CommerceTransactionPurchaseApi : CommerceTransactionApi
    {
        private PurchaseInput input;
        public PurchaseOutput output;

        private BillingInfo billingInfo;
        private CallerInfo callerInfo;
        private Marketplace marketPlace;
        private PurchaseContext purchaseContext;
        private PurchaseInfoInput purchaseInfo;


        public CommerceTransactionPurchaseApi(BasicHttpBinding binding, EndpointAddress address, X509Certificate2 clientCert, 
               BillingInfo billingInfo, CallerInfo callerInfo, Marketplace marketPlace, PurchaseContext purchaseContext, PurchaseInfoInput purchaseInfo)
            : base(binding, address, clientCert)
        {
            this.billingInfo = billingInfo;
            this.callerInfo = callerInfo;
            this.marketPlace = marketPlace;
            this.purchaseContext = purchaseContext;
            this.purchaseInfo = purchaseInfo;
        }

        protected override AbstractResponse ExecuteInternal(TransactionServiceChannel channel)
        {
            this.output = channel.Purchase(input);
            Console.WriteLine("purchase output:{0}", output.TotalPriceWithoutTax);
   
            return output;
        }

        public override void PrepareRequestData()
        {
            // prepare the create account input;
            this.input = new PurchaseInput()
            {
                APIContext = new APIContext()
                {
                    TrackingGuid = this.trackingGuid,
                },
                BillingInfo = this.billingInfo,
                CallerInfo = this.callerInfo,
                Marketplace = this.marketPlace,
                PurchaseContext = this.purchaseContext,
                PurchaseInfoInput = this.purchaseInfo
            };
        }

        public override void PrepareResponseData()
        {
            

            return;
        }
    }
}
